// ...
const adminAuth = require('./middlewares/admin-auth');
const UserAuth = require('./middlewares/user-auth');
const cors = require('cors');
// ...


var express = require('express');
var path = require('path');
var cookieParser = require('cookie-parser');
var logger = require('morgan');

var indexRouter = require('./routes/index');
var usersRouter = require('./routes/users');
// 后台路由文件
var adminArticlesRouter = require('./routes/articles');
var adminUsersRouter = require('./routes/admin/users');
var adminAuthRouter = require('./routes/auth');
var adminCommentsRouter = require('./routes/comments');
var LikesRouter = require('./routes/likes');

var app = express();
require('dotenv').config();
// CORS 跨域配置
app.use(cors());
app.use('/', indexRouter);

app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));

app.use('/',indexRouter);
app.use('/users', adminAuth,usersRouter);
app.use('/articles', adminAuth,adminArticlesRouter);
app.use('/admin/users', adminAuth,adminUsersRouter);
app.use('/comments', adminAuth, adminCommentsRouter);
app.use('/likes', UserAuth,LikesRouter);
app.use('/auth' ,adminAuthRouter);
module.exports = app;
